<template>
	<view>
		<div>
			<navitop> 
				<i class="iconfont icon-jiantou-copy" slot="left-slot" @click="outlot"></i>
				<span slot="center-slot">联系人详情</span>
				<i class="iconfont icon-youcecaidan" slot="right-slot" v-show="qp_alert"  @click="tapPopup(data)"></i>
			</navitop>
		</div>
		
		<div :style="'margin-top:' + nv_height"></div>
		
		<div class="public_list_style ">
			
			<div class="public_list_out" v-for="(item,index) in results">
				<div class="public_list"  v-if="item.code !== 'isMain' && item.code !== 'gender' && item.dataType == 1 && item.onEdit == 1">
					<div class="public_list_left">
						<text >{{item.name}}:</text>
					</div>
					<div class="public_list_right">
						<input type="text"  :value="item.value" disabled=true >
					</div>
				</div>
				<div  class="public_list" v-else-if="item.code == 'gender'">e
					<div class=" public_list_left">
						<text >{{item.name}}:</text>
					</div>
					<div class="public_list_right">
						<input type="text"  :value="item.value == '男' ? '男' : '女'" disabled=true >
					</div>
				</div>
				<div  class="public_list"  v-else-if="item.dataType == 2">
					<div class=" public_list_left">
						<text >{{item.name}}:</text>
					</div>
					<div class="public_list_right">
						<input type="text"  :value="item.values" disabled=true >
					</div>
				</div>
				<!-- <div v-else>
					<text >{{item.name}}:</text><input type="text"  :value="item.value ? '是' : '否'" disabled=true >
				</div> -->
			</div>
			
		</div>
		
		
		<chunLeiPopups v-model="value" :popData="data" @tapPopup="tapPopup" :x="345" :y="95" placement="top-end"></chunLeiPopups>
		
	</view>
</template>

<script>
	import navitop from '@/components/common/navi-top'
	import chunLeiPopups from "@/components/chunLei-popups/chunLei-popups.vue"
	import popus from '@/uni_modules/uni-popup/components/uni-popup/uni-popup'
	import typeinput from '@/pages/common/common/public_input/type_input'
	import {detail,save,namelist,userdetail,stpdel,list,getUserInfo} from '@/common/api/job/jobapi.js'
	export default {
		components:{
			navitop,
			popus,
			chunLeiPopups,
			typeinput
		},
		data(){
			return {
				dataSorce: [],
				results: [],
				data: [],
				uid: '',
				tpid: '',
				value: false,
				url: '',
				qp_alert: true,
				nv_height:''
			}
		},
		onLoad(option) {
			this.uid = option.id;
			this.tpid = option.uid;
			this.url = '&crmType=' + option.crmType + '&name=' + option.name + '&classid=' + option.classid
			this.getpost();
			
			this.qp_list(option.crmType);
		},
		mounted() {
			this.nv_height = uni.getSystemInfoSync().statusBarHeight + 75 + 'px';
		},
		methods:{
			// 显示气泡列表
			qp_list(val){
				if(val == 0){	// 公海
					let spto = [
						{title:"编辑",code:2,icon: 'icon-bianji',msg_code: 'crm:clue:linkMan:edit' },
						{title:"删除",code:3,icon: 'icon-shanchu',msg_code: 'crm:clue:linkMan:disable' },
					];
					this.get_userInfo(spto);
				}
				if(val == 1){	// 潜在
					let spto = [
						{title:"编辑",code:2,icon: 'icon-bianji',msg_code: 'crm:potential:linkMan:edit' },
						{title:"删除",code:3,icon: 'icon-shanchu',msg_code: 'crm:potential:linkMan:disable' },
					];
					this.get_userInfo(spto);
				}
				if(val == 2){	// 成交
					let spto = [
						{title:"编辑",code:2,icon: 'icon-bianji',msg_code: 'crm:deals:linkMan:edit' },
						{title:"删除",code:3,icon: 'icon-shanchu',msg_code: 'crm:deal:linkMan:disable' },
					];
					this.get_userInfo(spto);
				}
			},
			
			// 权限控制
			get_userInfo(spto){
				let sotrt = [];
				getUserInfo().then((rows) => {
					if(rows.code == 200) {
						rows.data.permissions.forEach(item => {
							spto.forEach(vals =>{
								if(item == vals.msg_code){
									sotrt.push(vals);
								}
							})
						})
					}
					if(sotrt == 0){
						this.qp_alert = false;
					}else {
						this.qp_alert = true;
					}
					this.data = sotrt;
				})
			},
			
			// 返回
			outlot(){
				uni.navigateTo({
				    url: '/pages/common/index/detial?id=' + this.tpid + this.url + '&index=' + 0
				});
			},
			open() {
			     this.$refs.popup.open('right')
			},
			closes(){
				this.$refs.alert.close();
			},
			getpost(){ 
				list({source: 'linkMan'}).then((rows) => {
					if (rows.code === 200) {
						userdetail({id: this.uid}).then((result) => {
							if (result.code == 200) {
								if(result.data.defineFields !== '' && result.data.defineFields !== null && result.data.defineFields !== undefined){
									result.data.defineFields = JSON.parse(result.data.defineFields);
								}
								rows.data.forEach(item => {
									if (item.code.indexOf('Id') != '-1') {
										let tempname = item.code.substring(0,item.code.length - 2) + 'Name';
										this.$set(item, 'value', result.data[tempname])
									}else{
										this.$set(item, 'value', result.data[item.code])
										if(result.data.defineFields !== '' && result.data.defineFields !== null && result.data.defineFields !== undefined){
											this.$set(item, 'values', result.data.defineFields[item.id])
										}
									}
								})
								this.results = rows.data;
							}
							
						})
						
					}
				})
			},
			
			tapPopup(val){
				this.value = true;
				if(val.code == 2){
					uni.navigateTo({
						url: '/pages/common/index/contactedits?id=' + this.uid + '&uid=' + this.tpid + this.url 
					})
				}
				if(val.code == 3) {
					stpdel({ids:this.uid}).then((reslut)=>{
						uni.showToast({
							title: '已删除'
						})
						setTimeout(() => {
							uni.navigateTo({
							    url: '/pages/common/index/detial?id=' + this.tpid + this.url + "&index=" + 1
							});
						},1500)
					})
				}
			}
		}
	}
	
</script>

<style scoped lang="scss">
</style>
